﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ordinaire.Commerce
{
    /// <summary>
    /// Represents an invoice header.
    /// </summary>
    public class Invoice : Entity<int>
    {
        /// <summary>
        /// Gets or sets the data unique identifier of an invoice.
        /// </summary>
        public override int Id
        {
            get { return base.Id; }
            set { base.Id = value; }
        }

        /// <summary>
        /// Gets or sets the invoice number.
        /// </summary>
        public string SerialNo { get; set; }

        /// <summary>
        /// Gets or sets the date of the invoice.
        /// </summary>
        public DateTime Date { get; set; }
        
        /// <summary>
        /// Gets or sets the party, as vendor or customer, who sells or buys goods under this invoice.
        /// </summary>
        public Entity<int> Party { get; set; }

        /// <summary>
        /// Gets or sets the invoice details: goods sold or bought.
        /// </summary>
        public List<InvoiceDetail> Details { get; set; }

        /// <summary>
        /// Gets or sets the discount percentage given against the total value of good contained in this invoice.
        /// </summary>
        public decimal DiscountPercentage { get; set; }

        /// <summary>
        /// Gets or sets the actual discount amount given against the total value of good contained in this invoice.
        /// </summary>
        public decimal Discount { get; set; }

        /// <summary>
        /// Gets or sets the tax percentage charged for this invoice.
        /// </summary>
        public decimal TaxPercentage { get; set; }

        /// <summary>
        /// Gets or sets the actual tax amount charged for this invoice.
        /// </summary>
        public decimal Tax { get; set; }

        /// <summary>
        /// Gets the value of this invoice after discount and gst.
        /// </summary>
        public decimal Value
        {
            get { return Details.AsEnumerable().Select(d => d.Value).Sum() + Tax - Discount; }
        }
    }
}
